//
//  CMSChartsTimeShareView.m
//  CMSCharts
//
//  Created by symbio on 2023/3/8.
//

#import "CMSChartsTimeShareView.h"
#import "CMSChartsContainerView.h"
#import <Masonry/Masonry.h>
#import <CMSFoundation/CMSFoundation.h>
#import <CMSUIKit/CMSUIKit.h>
#import "CMSChartsGradeView.h"
#import "CMSCharts-Swift.h"

@interface CMSChartsTimeShareView ()

/// 主图
@property (nonatomic, strong) CMSChartsContainerView *mainContainerView;
/// 竞价
@property (nonatomic, strong) CMSChartsContainerView *biddingContainerView;

/// 档次视图
@property (nonatomic, strong) CMSChartsGradeView *gradeView;

@end

@implementation CMSChartsTimeShareView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    [self addSubview:self.gradeView];
    [self.gradeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.right.bottom.equalTo(self);
        make.width.equalTo(self.mas_width).multipliedBy(0.3);
    }];
    
    [self addSubview:self.biddingContainerView];
    [self.biddingContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self);
        make.width.mas_equalTo(CMSChartsTool.showBidding ? 80 : 0);
    }];
    
    [self addSubview:self.mainContainerView];
    [self.mainContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.equalTo(self);
        make.right.equalTo(self.gradeView.mas_left);
        make.left.equalTo(self.biddingContainerView.mas_right);
    }];
}

- (CMSChartsGradeView *)gradeView {
    if (!_gradeView) {
        _gradeView = [[CMSChartsGradeView alloc] init];
    }
    return _gradeView;
}

- (void)setContainerModels:(NSArray<CMSChartsContentModel *> *)containerModels {
    _containerModels = containerModels;
    self.mainContainerView.containerModels = containerModels;
    self.biddingContainerView.containerModels = containerModels;
}

#pragma mark - 混合副图指标

- (CMSChartsContainerView *)biddingContainerView {
    if (!_biddingContainerView) {
        _biddingContainerView = [[CMSChartsContainerView alloc] init];
    }
    return _biddingContainerView;
}

#pragma mark - K线主视图

- (CMSChartsContainerView *)mainContainerView {
    if (!_mainContainerView) {
        _mainContainerView = [[CMSChartsContainerView alloc] init];
        @weakify(self);
        _mainContainerView.didSelectTagBlock = ^(CombinedChartView * _Nonnull chartsView, NSInteger viewIndex, NSInteger tagIndex, NSString * _Nonnull tag) {
            @strongify(self);
            CMSChartsTool.showBidding = !CMSChartsTool.showBidding;
            [self.biddingContainerView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.width.mas_equalTo(CMSChartsTool.showBidding ? 80 : 0);
            }];
        };
    }
    return _mainContainerView;
}
@end


